﻿<%@ Page Language="VB" AutoEventWireup="false" CodeFile="AddFundCenterToCmmt.aspx.vb" Inherits="AddFundCenterToCmmt" %>
 
 

<%@ Register Assembly="ISNet.WebUI.WebTreeView" Namespace="ISNet.WebUI.WebTreeView" TagPrefix="ISWebTreeView" %>

<%@ Register Assembly="ISNet.WebUI.WebGrid" Namespace="ISNet.WebUI.WebGrid" TagPrefix="ISWebGrid" %>

<%@ Register Assembly="ISNet.WebUI.WebCombo" Namespace="ISNet.WebUI.WebCombo" TagPrefix="ISWebCombo" %>

<%@ Register Assembly="ISNet.WebUI.WebDesktop" Namespace="ISNet.WebUI.WebDesktop" TagPrefix="ISWebDesktop" %>

<!DOCTYPE html>


<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head2" runat="server">
    <title></title>
    <link href="css/style.css" rel="stylesheet" />
       <script type="text/javascript" src="js/JSON.js"></script>
       <script>

           function WebGrid123_OnRowValidate(rowObject) {
               // retrieves WebGrid's object
               var grid = ISGetObject("WebGrid123");

               // access WebGrid's RootTable
               var rootTable = grid.RootTable;

               var row = rootTable.ToRowObject(rowObject); // convert the rowObject (HTMLElement) to WebGridRow object
               var htmlRow = row.GetElement();
               var cells = row.GetCells(); // get collection of WebGridCell
               var error = 0;


               //alert("1");
               var data
               data = wgGetCellByPosition(htmlRow, 2).innerText;
               if (data.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g, '').replace(/\s+/g, ' ') == "") {
                   alert("กรุณาระบุ จาก Fund Center");
                   error = error + 1;
               }
               data = wgGetCellByPosition(htmlRow, 3).innerText;
               if (data.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g, '').replace(/\s+/g, ' ') == "") {
                   alert("กรุณาระบุ ถึง Fund Center");
                   error = error + 1;
               }

               //alert("2");
               if (error == 0) {
                   return true;
               } else {
                   return false;
               }

           }

           function WebGrid123_OnEditKeyDown(controlId) {
               //alert(event.keyCode);
               var grid = ISGetObject("WebGrid123");

               var totalRows = grid.TotalRows;
               var totalCells = grid.TotalCells;
               var curRow = grid.GetSelectedObject().rowIndex;
               var curCell = grid.GetActiveEditCell().cellIndex;

               // if enter key
               if (event.keyCode == 13) {
                   if (totalRows >= 2) {
                       if (curRow < totalRows - 1) {
                           keyDown(curRow, curRow + 1, curCell - 1);
                       }
                   }
                   //grid.ExitEdit(1,0,0);
                   //return false;
                   //var ar = grid.GetSelectedObject().GetRowElement();

                   //if (ar.IsAddNewRow) {
                   //    ar.commit();
                   //}
                   //else {
                   //    event.keyCode = 40;
                   //    keyDown(curRow, curRow + 1, curCell - 1);
                   //}
               }

                   // if up arrow
               else if (event.keyCode == 38 && grid.GetSelectedObject().GetRowObject().Type != "NewRow") {
                   if (totalRows >= 2) {
                       if (curRow > 0) {
                           keyDown(curRow, curRow - 1, curCell - 1);
                       }
                   }
               }

                   // if down arrow key
               else if (event.keyCode == 40 && grid.GetSelectedObject().GetRowObject().Type != "NewRow") {
                   if (totalRows >= 2) {
                       if (curRow < totalRows - 1) {
                           keyDown(curRow, curRow + 1, curCell - 1);
                       }
                   }
               }
                   // if left arrow key
               else if (event.keyCode == 37) {

                   if (curCell > 1) {
                       //jq(document).trigger(jq.Event('keydown', { keyCode: 9, shiftKey: true }));
                       //var press = jQuery.Event("keydown");
                       //press.shiftKey = false;
                       //press.which = 9;
                       //jq("WebGrid123").trigger(press);
                       //alert("x");
                       //return;
                       keyDown2(curRow, curCell - 2);

                   }
               }
                   // if right arrow key
               else if (event.keyCode == 39) {
                   //if (curCell < totalCells - 1) {
                   event.keyCode = 9;
                   return true;
                   //}
               }


           }

           function keyDown(curRow, nextRow, cell) {
               var grid = ISGetObject("WebGrid123");
               var nextRowEl = grid.RootTable.GetRow(nextRow);
               var curRowEl = grid.RootTable.GetRow(curRow);
               var cell1 = nextRowEl.GetCell(cell);
               var cell2 = curRowEl.GetCell(cell);
               grid.ExitEdit(1, 0, 0);
               grid.SetFocus();

               cell2.Select(true);

               nextRowEl.Select();

               cell1.ActivateEdit();
           }
           function keyDown2(curRow, cell) {
               var grid = ISGetObject("WebGrid123");

               var selectedObject = grid.GetSelectedObject(); // return object of type SelectedObject
               var selectedRow = selectedObject.ToRowObject();
               var cell1 = selectedRow.GetCell(cell);
               grid.SetFocus();
               cell1.Select(true);
               cell1.ActivateEdit();

           }

           function triggerKeyEvents(field, keyCode, shiftKey, ctrlKey) {

               field = $(field);

               shiftKey = Boolean(shiftKey);

               ctrlKey = Boolean(ctrlKey);


               field.simulate("keydown", {
                   keyCode: keyCode,

                   ctrlKey: ctrlKey,

                   shiftKey: shiftKey
               });

               field.simulate("keypress", {
                   keyCode: keyCode,

                   ctrlKey: ctrlKey,

                   shiftKey: shiftKey
               });


               if (field.is(HTML5_TEXT_INPUT_FIELD_SELECTOR)) {

                   applyKeyCodeToValue(field, keyCode);

               }


               field.simulate("keyup", {
                   keyCode: keyCode,

                   ctrlKey: ctrlKey,

                   shiftKey: shiftKey
               });

           }

           function SaveScrollPosition(gridId, action) {
               // collecting the last position
               // of the vertical scrollbar
               // by obtaining the scrollTop property
               var grid = ISGetObject(gridId);
               // obtain the scrollTop and scrollLeft property 
               // of the vertical scrollbar and horizontal scrollbar
               var vl = grid.RootTable.GetElement(WG40.BODY, WG40.HTMLDIV).scrollTop + "";
               var hl = grid.RootTable.GetElement(WG40.BODY, WG40.HTMLDIV).scrollLeft + "";
               // only send the scrollTop property
               // of the server if the action performed
               // by the grid OTFPB is 'Refresh'

               //if (action == "Refresh") {
               // sending over the scrollTop and scrollLeft property
               // to the server by using AddInput method
               grid.AddInput("scrollTopPos", vl);
               grid.AddInput("scrollLeftPos", hl);
               //}

               return true;
           }
           function ApplyLatestScroll(gridId, y, x) {
               // set back the previous scrollTop and scrollLeft property or
               // vertical and horizontal scroll position with 
               // the parameter sent from the server side
               var grid = ISGetObject(gridId);
               // manually configure the vertical and horizontal scroll position
               grid.RootTable.GetElement(WG40.BODY, WG40.HTMLDIV).scrollTop = y;
               grid.RootTable.GetElement(WG40.BODY, WG40.HTMLDIV).scrollLeft = x;

               var cellEl = grid.GetActiveEditCell().ToCellObject();
               grid.SetFocus();
               cellEl.ActivateEdit();
               return true;
           }


           function CustomRequestDel(del) {

               if (confirm('กรุณายืนยันการลบข้อมูล') == false) {
                   return false
               }
               var grid = ISGetObject("WebGrid123");


               grid.AddInput("id", del);
               //alert(del);
               grid.AddInput("type", "1");
               grid.SendCustomRequest();



               event.cancelBubble = true;
               event.returnValue = false;
           }

           function closeJS2() { }
           function popuplistUFC(id, idyear, fcode) {
               var grid = ISGetObject("WebGrid123");
               var row = grid.GetSelectedObject().GetRowObject();
               var key = row.KeyValue;

               //get the key value of selected row.
               TINY.box.show({ iframe: 'mtUsersFCListPopup.aspx?UID=' + id + "&IDYear=" + idyear + "&FCode=" + fcode + "", boxid: 'frameless', width: 380, height: 370, fixed: false, maskid: 'lightmask', maskopacity: 40, closejs: function () { } })
           }
           function CustomRequestChkDel() {
               if (confirm('กรุณายืนยันการลบข้อมูล') == false) {
                   return false
               }
               var grid = ISGetObject("WebGrid123");
               var table = grid.GetRootTable();
               var checkedRows = table.GetCheckedRows();

               if (checkedRows.length == 0) {
                   alert("Please check an item.");
                   setTimeout(function () { grid.SetFocus(); }, 10);
               }
               else {

                   grid.AddInput("type", "2");
                   //alert("gfgfgfg");
                   grid.SendCustomRequest();

               }


               event.cancelBubble = true;
               event.returnValue = false;
           }
    </script>
</head>

<body>
    <form id="form2" runat="server">
        
       <div style="text-align: right; float: left; width: 97%; margin-left: 6px; border: solid; border-color: gray; border-width: 1px; margin-top: 10px; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; box-shadow: 5px 5px 5px #808080; padding: 5px 5px 5px 5px;">


            <table style="width:100%">
                <tr>
                    <td style="text-align:left">
                        <label >กำหนด FundCenter</label>
                     </td>
                    <td style="text-align:right">
                        <asp:ImageButton ID="SaveBtn" runat="server" ImageUrl="Icons/save.jpg" />
                        &nbsp;<asp:ImageButton ID="delete_btn" runat="server" ImageUrl="Icons/delete.jpg" OnClientClick="CustomRequestChkDel(); return false" />
                        &nbsp;<asp:ImageButton ID="CancelBtn" runat="server" ImageUrl="Icons/cancel.png" />
                    </td>
                </tr>
            </table>
        </div>
        <br />
        <br />
       <div style="float: left; width: 97%; margin-left: 6px; border: solid; border-color: gray; border-width: 1px; margin-top: 10px; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; box-shadow: 5px 5px 5px #808080; padding: 5px 5px 5px 5px;">
            <ISWebGrid:WebGrid ID="WebGrid123" runat="server" UseDefaultStyle="True" Width="100%" DefaultStyleMode="Silver" Height="390px" OnAddRow="WebGrid123_AddRow" OnUpdateRow="WebGrid123_UpdateRow" OnInitializePostBack="WebGrid123_InitializePostBack"   OnInitializeRow="WebGrid123_InitializeRow">
                <LayoutSettings AllowAddNew="No" EditOnClick="True" AllowColumnMove="No"
                    AllowEdit="Yes" AllowDelete="Yes" AllowSorting="Yes" ColumnFooters="Yes" NewRowLostFocusAction="AlwaysUpdate"
                    ResetNewRowValuesOnError="False" InProgressUIBehavior="ChangeCursorToHourGlass"
                    AlwaysShowHelpButton="false" PagingMode="ClassicPaging" PagingSize="12" ColumnFooterAggregateMode="CalculateAllData"
                    VirtualLoadMode="LargeData" AllowGrouping="Yes" VirtualPageSize="12" PagingLoadMode="Automatic">
                    <RowStyle Font-Names="Tahoma" Font-Size="9" CustomRules="overflow: hidden;" />
                    <AlternatingRowStyle Font-Names="Tahoma" Font-Size="9" BackColor="#fbfbfb" CustomRules="overflow: hidden;" />
                    <ClientSideEvents OnRowValidate="WebGrid123_OnRowValidate" OnEditKeyDown="WebGrid123_OnEditKeyDown" />
                </LayoutSettings>
                <RootTable DataKeyField="Id" NewRowInfoText="เพิ่มรายการ" >
                    <Columns>
                         <ISWebGrid:WebGridColumn IsRowChecker="true" Name="checker">
                        </ISWebGrid:WebGridColumn>
                        <ISWebGrid:WebGridColumn Caption="Id" DataMember="Id" Name="Id" Width="80" EditType="NoEdit">
                            <HeaderStyle HorizontalAlign="Center" />
                            <CellStyle HorizontalAlign="Center" />
                        </ISWebGrid:WebGridColumn>
                        <ISWebGrid:WebGridColumn Caption="จาก Fund Center" Name="FromFundCenter_FundCenterCode" DataMember="FromFundCenter_FundCenterCode" Width="300px" EditType="WebComboNET" WebComboID="FundCenterCombo">
                            <HeaderStyle HorizontalAlign="Center" />
                            <CellStyle HorizontalAlign="Left" />
                            <ValueList DataTextField="Description" DataSourceID="FundCenterDataSource"
                                DataValueField="FundCenter_FundCenterCode">
                            </ValueList>
                        </ISWebGrid:WebGridColumn>
                        <ISWebGrid:WebGridColumn Caption="ถึง Fund Center" Name="ToFundCenter_FundCenterCode" DataMember="ToFundCenter_FundCenterCode" Width="300px" EditType="WebComboNET" WebComboID="FundCenterCombo2">
                            <HeaderStyle HorizontalAlign="Center" />
                            <CellStyle HorizontalAlign="Left" />
                            <ValueList DataTextField="Description" DataSourceID="FundCenterDataSource"
                                DataValueField="FundCenter_FundCenterCode">
                            </ValueList>
                        </ISWebGrid:WebGridColumn>

                        <ISWebGrid:WebGridColumn Caption=" " ColumnType="Template" Name="Attachment" Width="50" EditType="NoEdit">
                            <CellTemplate>
                                <a href="#" style="text-decoration: none; border: none;">
                                    <img src="Icons/ic_deleteRed.png" height="16px" id='<%# Eval("Id")%>' style="text-decoration: none; border: none;" title="ลบ" onclick="CustomRequestDel(id);" />
                                </a>
                            </CellTemplate>
                            <CellStyle HorizontalAlign="Center"></CellStyle>
                        </ISWebGrid:WebGridColumn>
                    </Columns>
                </RootTable>
            </ISWebGrid:WebGrid>
            <ISWebCombo:WebCombo ID="FundCenterCombo" runat="server" UseDefaultStyle="True" DataTextField="Description" DataValueField="FundCenterCode" Height="20px" Width="200px" OnInitializeDataSource="FundCenterCombo_InitializeDataSource" AdditionalSearchFields="FundCenterCode">
                <LayoutSettings AlwaysShowAllRowsOnDropdown="true" AlwaysShowHelpButton="false" EntryMode="AutoComplete" ComboMode="MultipleColumns">
                </LayoutSettings>
                <Columns>
                    <ISWebCombo:WebComboColumn BaseFieldName="Description" Name="Description" HeaderText="ชื่อ FundCenter" Width="250px" />
                    <ISWebCombo:WebComboColumn BaseFieldName="FundCenterCode" Name="FundCenterCode" HeaderText="รหัส FundCenter" Width="80px" />
                </Columns>
            </ISWebCombo:WebCombo>
            <ISWebCombo:WebCombo ID="FundCenterCombo2" runat="server" UseDefaultStyle="True" DataTextField="Description" DataValueField="FundCenterCode" Height="20px" Width="200px" OnInitializeDataSource="FundCenterCombo2_InitializeDataSource" AdditionalSearchFields="FundCenterCode">
                <LayoutSettings AlwaysShowAllRowsOnDropdown="true" AlwaysShowHelpButton="false" EntryMode="AutoComplete" ComboMode="MultipleColumns">
                </LayoutSettings>
                <Columns>
                    <ISWebCombo:WebComboColumn BaseFieldName="Description" Name="Description" HeaderText="ชื่อ FundCenter" Width="250px" />
                    <ISWebCombo:WebComboColumn BaseFieldName="FundCenterCode" Name="FundCenterCode" HeaderText="รหัส FundCenter" Width="80px" />
                </Columns>
            </ISWebCombo:WebCombo>
            <asp:ObjectDataSource ID="FundCenterDataSource" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetData2" TypeName="BasicDataTableAdapters.FCTR_ValueTableAdapter">
                <SelectParameters>
                    <asp:SessionParameter Name="PlanYear" SessionField="PlanYear" Type="Int16" />
                </SelectParameters>
            </asp:ObjectDataSource>
        </div>

        <script>

            //var combo1 = document.getElementById("WebCombo3");
            //combo1.style.height = "20px";



        </script>
       
        <style>
            .WC4-DD-N {
                height: 0px;
            }

            .WC4-DD-A {
                height: 0px;
            }
        </style>
    </form>
</body>
</html>